package com.example.myview;


import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;

public class MyView extends View {
    private final String TAG = "MyView";
    private Paint paint = new Paint();
    private int value;
    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(10);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setTextSize(20);

        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 500);
        valueAnimator.setDuration(5000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                value = (int) animation.getAnimatedValue();
                invalidate();
            }
        });
        valueAnimator.setRepeatCount(-1);
        valueAnimator.start();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawCircle(value,value,50,paint);


        /*Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.cat);
        canvas.drawBitmap(bitmap,value,value,paint);*/

//        canvas.drawColor(Color.BLUE);

//        canvas.drawLine(50,50,150,150,paint);
//        canvas.drawRect(100,100,400,400,paint);

        /*RectF rectF = new RectF(100,100,400,400);
        canvas.drawRoundRect(rectF,50,50,paint);*/

//        canvas.drawCircle(100,100,50,paint);

//        canvas.drawArc(100,100,300,300,225,90,true,paint);
//        canvas.drawPoint(200,200,paint);

        /*Path path = new Path();
        path.lineTo(100,100);
        path.lineTo(100,300);
        path.lineTo(200,500);
        canvas.drawPath(path,paint);*/


//        canvas.drawText("hello world",200,200,paint);

       /* Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.cat);
        Matrix matrix2 = new Matrix();
        matrix2.setScale(-0.5f, 0.5f);
        matrix2.postTranslate(495, 0);
        canvas.drawBitmap(bitmap, matrix2, paint);

        Matrix matrix3 = new Matrix();
        matrix3.setScale(0.5f, -0.5f);
        matrix3.postTranslate(0, 495);
        canvas.drawBitmap(bitmap, matrix3, paint);

        Matrix matrix4 = new Matrix();
        matrix4.setScale(-0.5f, -0.5f);
        matrix4.postTranslate(495, 495);
        canvas.drawBitmap(bitmap, matrix4, paint);*/


        /*Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.cat);
        Matrix matrix = new Matrix();
        canvas.drawBitmap(bitmap, matrix, paint);
        matrix.setRotate(90, 225, 225);

        canvas.drawBitmap(bitmap, matrix, paint);
        matrix.setRotate(180, 225, 225);

        canvas.drawBitmap(bitmap, matrix, paint);
        matrix.setRotate(270, 225, 225);

        canvas.drawBitmap(bitmap, matrix, paint);*/
    }
}
